console.log('2, helloworld')

function add7(x: number, ...rest: number[]) {
    return x + rest.reduce((pre, cur) => pre + cur)
}

console.log(add7(1, 2, 3, 4, 5))


/**
 * 函数重载
 * @param rest 
 */
function add8(...rest: number[]) : number
function add8(...rest: string[]) : string
function add8(...rest: any[]): any {
    let first = rest[0]
    if (typeof first === 'string') {
        return rest.join('')
    }
    if (typeof first === 'number') {
        return rest.reduce((pre, cur) => pre + cur)
    }
}

console.log(add8('hello ', 'world'))
console.log(add8(1, 2, 3))




